package com.example.kliven.because.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.example.kliven.because.R;
import com.example.kliven.because.Singleton.VolleySingleton;
import com.example.kliven.because.bean.HealthBean;

import java.util.List;

/**
 * Created by Kliven on 16/1/15.
 */
public class HealthAdapter extends BaseAdapter {

    private Context context;
    private List<HealthBean> healthBeans;

    public HealthAdapter(Context context, List<HealthBean> healthBeans) {
        this.context = context;
        this.healthBeans = healthBeans;
        VolleySingleton.getInstance();
    }

    @Override
    public int getCount() {
        return healthBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return healthBeans;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        HealthViewHodler healthViewHodler;
        String img = healthBeans.get(i).getMain_img_url();
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_lv_health, viewGroup, false);
            healthViewHodler = new HealthViewHodler(view);
            view.setTag(healthViewHodler);
        } else {
            healthViewHodler = (HealthViewHodler) view.getTag();
        }

        healthViewHodler.tv_title_health.setText(healthBeans.get(i).getTitle());
        healthViewHodler.iv_img_url_health.setImageUrl(img, VolleySingleton.getImageLoader());
        return view;
    }

    class HealthViewHodler {
        TextView tv_title_health;
        NetworkImageView iv_img_url_health;

        public HealthViewHodler(View view) {
            tv_title_health = (TextView) view.findViewById(R.id.tv_titile_health);
            iv_img_url_health = (NetworkImageView) view.findViewById(R.id.net_img_health);
        }
    }
}
